//app.js
const SPECIAL_SCENE_VALUES = [ 1011, 1013, 1025, 1031, 1032, 1048, 1049 ];

App({
  onLaunch: function (e) {
    const scene = e.scene;
    this.globalData = {};
    if (!wx.cloud) {
      console.error('请使用 2.2.3 或以上的基础库以使用云能力')
    } else {
      wx.cloud.init({
        env: 'libusr32-cloud',
        traceUser: true,
      });
      const cred = require('./utils/credentials');
      cred.refreshOpenId().catch(err => {
        console.log(err);
      });
      // auto login?
      cred.isUserAuthorized().then(flag => {
        if (flag) {
          cred.refreshUserInfo().catch(e => console.log(e));
        }
      }).catch(e => console.log(e));
      if (scene in SPECIAL_SCENE_VALUES) {
        const query = e.query;
        // TODO: goto certain page with query value
        console.log(query);
      }
    }
  }
});
